/****************************************************************
 * I am the AC 130 vs Pirate game. I allow the user to control an 
 * AC130 gunship in the hunt for Modern day pirates. The player  
 * will be allowed to roam free across a section of ocean/coastline.  
 * In the water there will be four types of vessels: Merchant  
 * ships that the player must protect, Pirate ships that the player  
 * must identify and destroy, Fishing boats that look like Pirate  
 * ships that the player must not destroy, and Friendly Navy ships  
 * that can capture pirates for extra points. Time permitting there  
 * may also be ground targets to attack. 
 *
 * Key elements of this project will be the Player/AC130, the Ships,  
 * the ShipAI system, the collision grid, the debris controller, the  
 * Ground/Water, Clouds, and scoring system. This project will make  
 * use of an external text file to store useful game parameters,  
 * thus allowing us to play balance the game without recompiling  
 * the executable. 
 *****************************************************************
 * I am the World class. I contain all objects that comprise the 
 * game world.
 *****************************************************************/

#include "World.h"


/*****************************************************************
 * I am the Consstructor I create all internal components of the
 * world in memory
 *****************************************************************/
World::World(){
	cam = new Camera;
	MouseLoc = new Point;
	Help = new Point;
}


/*****************************************************************
 * I am the desctructor. I clean up all memory initilzed in the
 * constructor
 *****************************************************************/
World::~World(){
	
}

/*****************************************************************
 * I am the Update function I process all timer and postion related
 * stuff
 *****************************************************************/
void World::Update(){
	poll_joystick();

		// test code
	if(mouse_b&1 > 0){
		MouseLoc->x = (mouse_x)-SCREEN_W/2;
		MouseLoc->y = (mouse_y)-SCREEN_H/2;
	}
}

	// I am the edit function
void World::UpdateEdit(){


	
}

/*****************************************************************
 * I am the Input Processor. I send the appropriate messags to
 * the world's objects based on key and joystick states
 *****************************************************************/
void World::ProcInput(){
		// check mouse place
	if(mouse_b&1 > 0){
		//myYetiCtrl->worker[0]->Spawn(cam->STWx(mouse_x), cam->STWy(mouse_y));
		//myPlayer->center->x = mouse_x*2;
		//myPlayer->center->y = mouse_y*2;
	}
		// this is how you process joystick input
	/*poll_joystick();
	myPlayer->inLeft = key[KEY_LEFT] || joy[0].stick[0].axis[0].d1;
	myPlayer->inRight  = key[KEY_RIGHT] ||joy[0].stick[0].axis[0].d2;
	myPlayer->inUp = key[KEY_UP] || joy[0].stick[0].axis[1].d1;
	myPlayer->inDown = key[KEY_DOWN] || joy[0].stick[0].axis[1].d2;
	myPlayer->inJump = key[KEY_SPACE]|| key[KEY_X] || joy[0].button[1].b;
	myPlayer->inAttack = key[KEY_Z] ||  joy[0].button[0].b;*/


}


/*****************************************************************
 * I am the Draw Function. I render the world in the propper order
 * to give things a sense of overlapping.
 *****************************************************************/
void World::Draw(){
	clear_to_color(cam->screen, makecol(0, 0, 155));
	textprintf_ex(cam->screen, font, 1*SCREEN_W/7, 10, makecol(220, 220, 220),
				makecol(10, 10, 10),
				" X: %f  Y: %f ang: %f", (MouseLoc->x), (MouseLoc->y), cam->center->AngTo(MouseLoc));
	Help->x = 0; Help->y = 100;
	Help->RotateBy(cam->center->AngTo(MouseLoc));
	line(cam->screen, SCREEN_W/2, SCREEN_H/2, //mouse_x, mouse_y,makecol(255, 0, 0));
		(MouseLoc->x+SCREEN_W/2), (MouseLoc->y+SCREEN_H/2),makecol(255, 0, 0));
	line(cam->screen, SCREEN_W/2, SCREEN_H/2+5, //mouse_x, mouse_y,makecol(255, 0, 0));
		(Help->x+SCREEN_W/2), (Help->y+SCREEN_H/2+5),makecol(0, 255, 0)); 
	
}
